# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=pg_probackup
pkgver=2.5.5
_pgsqlver=14.4
_pgsqlverm="${_pgsqlver%%.[0-9]*}"
pkgrel=1
pkgdesc="Backup and recovery manager for PostgreSQL"
url="https://github.com/postgrespro/pg_probackup"
arch="all"
license="PostgreSQL"
makedepends="postgresql$_pgsqlverm postgresql$_pgsqlverm-dev zlib-dev readline-dev libxml2-utils libxslt"
subpackages="$pkgname-doc"
source="pg_probackup-$pkgver.tar.gz::https://github.com/postgrespro/pg_probackup/archive/refs/tags/$pkgver.tar.gz
	https://ftp.postgresql.org/pub/source/v$_pgsqlver/postgresql-$_pgsqlver.tar.bz2"
builddir="$srcdir/postgresql-$_pgsqlver/contrib/pg_probackup-$pkgver"

[ "$CARCH" = "riscv64" ] && options="$options textrels"

prepare(){
	default_prepare

	mv "$srcdir"/pg_probackup-$pkgver "$srcdir"/postgresql-$_pgsqlver/contrib

	cd "$srcdir"/postgresql-$_pgsqlver
	./configure --without-ldap

	local _header
	for _header in $(ls "$srcdir"/postgresql-$_pgsqlver/src/bin/pg_basebackup/*.h); do
		ln -s $_header "$builddir"/src/
	done
}

build() {
	make -j1

	cd doc
	xmllint --noout --valid probackup.xml
	xsltproc stylesheet.xsl probackup.xml >pg-probackup.html
}

check() {
	local _tmp=$(mktemp -u)
	local _catalog="$(pwd)$_tmp"
	./pg_probackup version
	./pg_probackup init -B $_catalog
}

package() {
	install -Dm755 ./pg_probackup \
		"$pkgdir"/usr/bin/pg_probackup$_pgsqlverm
	install -Dm644 "$builddir"/doc/pg-probackup.html "$pkgdir"/usr/share/doc/pg_probackup/pg-probackup.html
}

sha512sums="
5260b22982f3fc73176887c3162b47893c0d9b5d337121a8f769269af34225d9d0959461f2d3aeb498c59f91103a03442b4345ae3a2ad38b45ac0f78e23e1c53  pg_probackup-2.5.5.tar.gz
dd2f80248684e331d2ffb1e26cd2a285df1fb18710807a0c31aedabf917912ce9267f8ca26318e5371d916c6fe476f8a17886d82d3ff86a974e6f24c19a6aafb  postgresql-14.4.tar.bz2
"
